/* 
* Copyright (C) 2011-2018 ShenZhen iBOXSaaS Information Technology Co.,Ltd. 
* 
* All right reserved. 
* 
* This software is the confidential and proprietary 
* information of iBOXSaaS Company of China. 
* ("Confidential Information"). You shall not disclose 
* such Confidential Information and shall use it only 
* in accordance with the terms of the contract agreement 
* you entered into with iBOXSaaS inc. 
* 
*/

 package com.iboxpay.open.auth.center.basedata;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.iboxpay.open.common.db.dao.AppBaseInfoDao;
import com.iboxpay.open.common.db.dao.AuthTokenScopeDao;
import com.iboxpay.open.common.db.entity.AppBaseInfo;
import com.iboxpay.open.common.db.entity.AuthTokenScope;

/**
 * 
 * BaseData.java
 * @author xuxiao
 * @date 2018/06/19
 */
@Component
 public class BaseData {
    
    public Map<String, AuthTokenScope> scopeMap = new HashMap<>();
    
    public Map<Long, AppBaseInfo> appBaseInfoMap = new HashMap<>();
    
    @Autowired
    private AuthTokenScopeDao authTokenScopeDao;
    
    @Autowired
    private AppBaseInfoDao appBaseInfoDao;
    
    @PostConstruct
    public void init() {
        loadScope();
        loadAppBaseInfo();
    }
    
    private void loadScope() {
        Map<String, AuthTokenScope> tmp = new HashMap<>();
        List<AuthTokenScope> scopes = authTokenScopeDao.selectAll();
        for(AuthTokenScope entry : scopes) {
            tmp.put(entry.getScopeCode(), entry);
        }
        scopeMap.putAll(tmp);
    }
    
    private void loadAppBaseInfo() {
        Map<Long, AppBaseInfo> tmp = new HashMap<>();
        List<AppBaseInfo> appBaseInfos = appBaseInfoDao.selectAll();
        for(AppBaseInfo entry : appBaseInfos) {
            tmp.put(entry.getAppId(), entry);
        }
        appBaseInfoMap.putAll(tmp);
    }

}
